using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Runtime.Serialization;

namespace Rogue
{
    [Serializable]
    public struct MapCell : ISerializable
    {
        public string TerrainDefinition;
        public bool Mapped;
        public bool BlocksLight;
        public bool BlocksActor;

        public char TerrainUpTile;
        public Color TerrainUpColor;

        public char TerrainForegroundTile;
        public Color TerrainForeColor;
        
        public char TerrainBackgroundTile;
        public Color TerrainBackColor;
        
        public bool Bloody;

        public void Draw(TerrainWindow a_TerrainWindow, int a_nWindowX, int a_nWindowY)
        {
            a_TerrainWindow.PutChar(TerrainForegroundTile, a_nWindowX, a_nWindowY, TerrainForeColor);
        }

        #region Serialization
        public MapCell(SerializationInfo info, StreamingContext context)
        {
            TerrainDefinition = (string)info.GetValue("TerrainDefinition", typeof(string));
            Mapped = (bool)info.GetValue("Mapped", typeof(bool));
            
            TerrainDef def = TerrainDatabase.Instance.GetDefinition(TerrainDefinition);

            BlocksLight = def.BlocksLight;
            BlocksActor = def.BlocksActor;

            TerrainUpTile = (char)def.UpTile;
            TerrainUpColor = new Color(def.UpColor);

            TerrainForegroundTile = (char)def.ForegroundTile;
            TerrainForeColor = new Color(def.ForeColor);

            TerrainBackgroundTile = (char)def.BackgroundTile;
            TerrainBackColor = new Color(def.BackColor);
            
            Bloody = false;
        }

        public  void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("TerrainDefinition", TerrainDefinition);
            info.AddValue("Mapped", Mapped);
        }
        #endregion
    }
}
